<?php
/**
 * Baby组 类
 * @author :zhanghui 
 * @create_date 2008-02-29
 */

class BabyFriendGroup{
	function __construct(){}
	function __destruct(){}
	
	/* 添加Baby组
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,group_id,group_name,create_date
	*/
	function addBabyFriendGroup($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_friend_group";
		$str_query .= " set";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= ",group_name={$arr_input['group_name']}";
		$str_query .= ",create_date='".$conn->getCurrentTime()."'";
		
		$conn->executeQuery($str_query); 
	}
	
	/* 删除Baby组
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,group_id,group_name,create_date
	*/
	function deleteBabyFriendGroup($conn,$arr_input){
		$str_query = "delete from";
		$str_query .= " baby_friend_group";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		if(isset($arr_input['group_id'])){
			$str_query .= " and group_id={$arr_input['group_id']}";
		}
		
		$conn->executeQuery($str_query);
	}
	
	/* 编辑Baby组
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,group_id,group_name,create_date
	*/
	function editBabyFriendGroup($conn,$arr_input){
        $str_query = "update";
		$str_query .= " baby_friend_group";
		$str_query .= " set";
		$str_query .= " group_name={$arr_input['group_name']}";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= " and group_id={$arr_input['group_id']}";

		$conn->executeQuery($str_query);	
	}
	
	/* 获取Baby组
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,group_id,group_name,create_date
	* @return : $arr_output
    *			baby_id, 			[0]<br>
    *			group_id, 		    [1]<br>
    *			group_name, 		[2]<br>
    *			create_date, 		[3]<br>
	*/
	function getBabyFriendGroupList($conn,$arr_input,$limit = null){
		$str_query = "select";
		if(isset($arr_input['cnt'])){
			$str_query .= " count(1)";
		}else{
			$str_query .= " baby_id";
			$str_query .= ",group_id";
			$str_query .= ",group_name";
			$str_query .= ",create_date";
		}
		$str_query .= " from";
		$str_query .= " baby_friend_group";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		if(isset($arr_input['group_id'])){
			$str_query .= " and group_id={$arr_input['group_id']}";
		}
		if(isset($arr_input['orderby'])){
			$str_query .= " order by {$str_query['orderby']}";
		}
		if($limit != null){
			$str_query .= " {$limit}";
		}
		
		$arr_output = $conn->selectQuery($str_query);
		return $arr_output;
	}
	
	
}
?>